<%@ page language="java" contentType="text/html; charset=UTF-8"
   pageEncoding="UTF-8"%>
<%@taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html"%>
<%@taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean"%>
<%@ page import="ssi.beans.Animal" %>
<%@ page import="ssi.beans.User" %>
<%@ page import="ssi.tools.FavouritesChecking" %>
<%@ page import="ssi.tools.AdoptionChecking" %>
<%
Animal animal=new Animal();
String[] animals=animal.getAnimal(request.getParameter("id"));
String name=animals[0];
String gender=animals[1];
String birthDate=animals[2];
String breed=animals[3];
String filename=animals[4];
String adopted = animals[5];
%>
<script type="text/javascript" src="js/validate.js"></script>
<h2><%=breed %> - <%= name %></h2><br>
<center><img src="images/animals/<%=filename %>" class='image_frame_300'></center><br>
<center>
<table>
<tr>
<td><h3><font color="#75a62c">Płeć:</font></h3></td><td><h3> <%=gender %></h3></td>
</tr>
<tr>
<td><h3><font color="#75a62c">Rasa:</font></h3></td><td> <h3><%=breed %></h3></td>
</tr>
<tr>
<td><h3><font color="#75a62c">Data Urodzenia: </font></h3></td><td><h3> <%=birthDate %></h3></td>
</tr>
<tr>
<td><h3><font color="#75a62c">Imię:</font></h3></td><td><h3> <%=name %></h3></td>
</tr>
</table>
		<%if(session.getAttribute("user")!=null){ 
			User user =(User) session.getAttribute("user");	
			if(AdoptionChecking.IfAdopted(request.getParameter("id"), user.getId())==false ){
				if(adopted.equals("0")){
			%>
			<html:form action="adoption" onsubmit="return confirm('Jestes pewny?');">
				<input type="hidden" value="<%=request.getParameter("id") %>" name="animalID" id="animalID" />
				<input type="submit" class="submit2" value="Adoptuj zwierzaka"/>
				<font color="red"><html:errors property="error" /></font>
			</html:form>
			<% }else{ %>
				<p>Zwierzak juz został zaadoptowany</p>
				<%}}else{%>
			<html:form action='cancelAdoption' onsubmit="return confirm('Jestes pewny?');">
				<input type="hidden" value="<%=request.getParameter("id") %>" name="animalID" id="animalID" />
				<input type="hidden" value="<%=user.getId() %>" name="id" id="id"/>
				<input type="submit" class="submit2" value="Odwolaj adopcje" />
			</html:form>
			<%}
			if(FavouritesChecking.IfFavourite(request.getParameter("id"), user.getId())==false ){
			%>
			<html:form action="adToFavourites">
				<input type="hidden" value="<%=request.getParameter("id") %>" name="animalID" id="animalID" />
				<input type="submit" class="submit2" value="Dodaj do ulubionych" />
			</html:form>
			<% }else{%>
			<html:form action="cancelFavourites">
				<input type="hidden" value="<%=request.getParameter("id") %>" name="animalID" id="animalID" />
				<input type="hidden" value="<%=user.getId() %>" name="id" />
				<input type="submit" class="submit2" value="Usuń z ulubionych" />
			</html:form>
		<%}
		}else{%>
		Aby adoptowac zwierzaka musisz sie zalogowac!
		<%} %></center>


